<?php
	namespace Admin\Controller;
	use Think\Controller;
	class GongshiController extends Controller {

		public function index()
		{
			//查询       
         if ($_GET['sub']=="查询") {
                $key=$_GET['keywords'];
         		$type=$_GET['search'];
            $wheres['sname']=array('like',"%$key%");
            $wheres['stype']=$type;
            $wheres=array_filter($wheres); 
         }else{
            $wheres='';
         }

		$db=M("Shenhe"); // 实例化Plan对象
		$count      = $db->where($wheres)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(15)
		$show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$Uarr = $db->where($wheres)->order('createtime DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('Garr',$Uarr);// 赋值数据集    	   
		$this->assign('page',$show);// 赋值分页输出
		$this->display(); // 输出模板
		}
		public function shen($id)
		{
			$db=M("Shenhe"); 
			if (IS_POST) {
			$sid=I("post.usd");
			$data['yijian']=I("post.yuan");
			$data['status']=I("post.shen");
			array_filter($data);
			$list=$db->where('sid='.$sid)->save($data);
			if ($list) {	    
				    echo "<script>
				            alert('成功');
				            location.href='/Admin/Gongshi';//客户端跳转
				          </script>";
			}else{
				    echo "<script>
				            alert('失败');
				          </script>";
				}	   
			}else{
			$Uarr=$db->where('sid='.$id)->find();
			$this->Uarr=$Uarr;
			// $photo=M("Sphotos");
			// $Parr=$photo->where('sid='.$id)->select();
			$this->Parr=$Parr;
			$this->display();
		  }
		}
		public function up()
		{
			$wheres['sid']=I("post.sid");
			$data['stus']=I("post.sta");
			if (IS_POST) {
				$db=M("Shenhe"); 
				$list=$db->where($wheres)->save($data);
				if ($list) {
					echo "修改成功";
				}else{
					echo "修改失败";
				}
			}
		}

   // 删除
    public function delete($sid) {
        if (!empty($sid)) {
            $Form = M("Shenhe");
            $result = $Form->delete($sid);
            if (false !== $result) {
                echo '删除成功！';
            } else {
                echo '删除出错！';
            }
        } else {
            $this->error('ID错误！');
        }
    }
    public function bianji($id)
    {
    	$gongshi=M("Gongshi");
    	$Garr=$gongshi->where('sid='.$id)->find();
    	if(empty($Garr)){
    		$shen=M("Shenhe");
    		$Garr=$shen->where("sid=".$id)->find();
			$bao=M("Baodan")->field('addtime')->where("bid=".$Garr['bid'])->find();    	
			$this->bao=$bao;	
    	}

    	    echo "<pre>";
    		print_r ($Garr);
    		echo "</pre>";   
    	   
    	$this->Garr=$Garr;
    	$this->display();
    }


 public function file()
    {
        
        //加载文件上传，图片处理类
            import("@.ORG.UploadFile");
        //导入上传类
            $upload = new UploadFile();
        //设置上传文件大小
            $upload->maxSize=3292200;
        //设置上传文件类型
            $upload->allowExts=explode(',','jpg,gif,png,jpeg');
        //设置附件上传目录
            $upload->savePath='./Uploads/';
        //设置需要生成缩略图，仅对图像文件有效
            $upload->thumb = true;
        // 设置引用图片类库包路径
            $upload->imageClassPath ='@.ORG.Image';
        //设置需要生成缩略图的文件后缀
            $upload->thumbPrefix='m_,s_';  //生产2张缩略图
        //设置缩略图最大宽度
            $upload->thumbMaxWidth='400,100';
        //设置缩略图最大高度
            $upload->thumbMaxHeight='400,100';
        //设置上传文件规则
            $upload->saveRule='uniqid';
        //删除原图
            $upload->thumbRemoveOrigin=true;
          if( !$upload->upload() )
          {
              echo '0';
          }else{
              $info=$upload->getUploadFileInfo();
            $src='s_'.$info[0]['savename'];
            echo $src;
          }
    }

}